<%-- 
    Document   : buscaLogin
    Created on : 07/10/2010, 23:42:04
    Author     : RICARDO ROCHA
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%@ page contentType="text/html" language="java" import="java.sql.*" %>
        <%@ include file="Connections/oracle.jsp" %>
        <%
        int pagina = 1;
        int minRecords = 0;
        int maxRecords = 20;

        if (request.getParameter("pagina") !=null) {
           pagina = Integer.parseInt(request.getParameter("pagina"));
           maxRecords = pagina * 20;
           minRecords =  maxRecords - 20;
        }


        Statement stmtRecordsCount = adminConnection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        ResultSet recordsCount = stmtRecordsCount.executeQuery("SELECT * FROM usuario");
        boolean recordsCount_isEmpty = !recordsCount.next();
        int paginas = (recordsCount.getInt("COUNT")/20);

        Statement stmtDiccionario = adminConnection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        ResultSet diccionario = stmtDiccionario.executeQuery("SELECT * FROM ( SELECT a.*, ROWNUM RNUM FROM (SELECT * FROM DICCIONARIO ORDER BY TERMINO ASC) a WHERE ROWNUM <= " + maxRecords + ") WHERE RNUM > " + minRecords);
        %>

        <table border="1" cellpadding="2" cellspacing="2">
        <%
        diccionario.beforeFirst();
        while(diccionario.next()) {
        %>
          <tr>
            <td width="50%"><strong><%=diccionario.getInt("RNUM")%></strong> <%=diccionario.getString("TERMINO")%> </td>
          </tr>
        <%
        }
        %>
        </table>
        <%
        for (int p = 1; p <= paginas; p++) {
           if(pagina==p){
              out.print("<strong><a href=paginar.jsp?pagina=" + p + ">" + p + "</a></strong> ");
           } else {
              out.print("<a href=paginar.jsp?pagina=" + p + ">" + p + "</a> ");
           }
        }
        %>

        <%
        stmtDiccionario.close();
        diccionario.close();
        adminConnection.close();
        %>
    </body>
</html>
